package volkov.ja;

import org.openqa.selenium.By;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import volkov.ja.pages.TestBase;
import volkov.ja.util.TestLogger;

public class MovieCreateTest2 extends TestBase {
	private static TestLogger LOG;

	@BeforeClass
	public void prepareTest() {
		LOG = new TestLogger(MovieCreateTest1.class, getSessionId());
		loginTestApplication();
	}

	@Test
	public void tesMovieCreate1() throws Exception {
		String title = "Вечера на хуторе близ Диканьки";
		LOG.info("Go to the movies list");
		driver.get(baseUrl + "#!/sort/name%20asc/");
		LOG.info("Click on the \"add movie\" button");
		clickIfPresent(By.cssSelector("img[alt=\"Add movie\"]"));
		LOG.info("Fill the form for a new movie");
		driver.findElement(By.name("name")).clear();
		driver.findElement(By.name("name")).sendKeys(title);
		driver.findElement(By.name("year")).clear();
		driver.findElement(By.name("year")).sendKeys("1961");
		driver.findElement(By.name("notes")).clear();
		driver.findElement(By.name("notes")).sendKeys("some remarks");
		LOG.info("Submitting data for the new movie");
		driver.findElement(By.id("submit")).click();
		// check results
		LOG.info("Go to the movies list");
		driver.get(baseUrl + "#!/sort/name%20asc/");
		LOG.info("Check if the newly created movie is present in the list");
		checkElementWithContent(By.xpath("//div[contains(@class, 'movie_box')]//div[@class='title']"), title,
				"Movie creation failed. Expected movie title: \"" + title
						+ "\"");
	}

}
